package com.mogist.hqc.module.product.presenter

import com.google.gson.reflect.TypeToken
import com.mogist.hqc.entitys.BaseResponse
import com.mogist.hqc.entitys.response.ProductTypeVo
import com.mogist.hqc.module.product.contract.ProductListContract
import com.mogist.hqc.mvp.HttpDto
import com.mogist.hqc.mvp._PresenterImpl
import com.mogist.hqc.util.Constant
import talex.zsw.basecore.util.JsonTool

/**
 * 作用：玩家产品
 * 作者：赵小白 email:vvtale@gmail.com  
 * 修改人：
 * 修改时间：
 * 修改备注：
 */
class ProductListPresenter(view: ProductListContract.View) : _PresenterImpl<ProductListContract.View, BaseResponse>(
        view), ProductListContract.Presenter
{
    override fun requestSuccess(response: BaseResponse, http: HttpDto)
    {
        when (http.url)
        {
            Constant.PRODUCT_TYPES ->
            {
                if (response.success)
                {
                    val list =
                            JsonTool.getObject(response.content,
                                               object : TypeToken<ArrayList<ProductTypeVo>>()
                                               {})
                    mView.bindTypes(list as ArrayList<ProductTypeVo>?)
                }
                else
                {
                    mView.bindTypes(null)
                }
            }
        }
    }

    override fun requestError(msg: String?, httpDto: HttpDto?)
    {
        mView.bindTypes(null)
    }
}